import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { alternatives } from '..';
import { PermissionSchema } from '../../schema';

export class SavePermissionValidator implements PermissionSchema {
  @ApiProperty({
    type: 'string',
    title: '权限名称',
    example: 'null',
    description: '权限名称',
    required: true,
  })
  @Rule(RuleType.string().required())
  permissionName: string;

  @ApiProperty({
    type: 'string',
    title: '权限编码',
    example: 'null',
    description: '权限编码',
    required: true,
  })
  @Rule(RuleType.string().required())
  permissionCode: string;
}

export class EditPermissionValidator implements Partial<PermissionSchema> {
  @ApiProperty({
    type: 'string',
    title: '权限名称',
    example: 'null',
    description: '权限名称',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  permissionName?: string;

  @ApiProperty({
    type: 'string',
    title: '权限编码',
    example: 'null',
    description: '权限编码',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  permissionCode?: string;
}
